﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using InvokeWebService.Messages;
using PServiceBus.Services.Gateway.Runtime;

namespace WebServiceServer {
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService {

        static WebService1() {
            Topic.RegisterIfNotExist<WebServiceInvokeCompleted>();
        }

        [WebMethod]
        public void HelloWorld(HelloData data) {
            var msg = new WebServiceInvokeCompleted() { Message = String.Format("Hello World {0} from web service. {1}", data.Text,
                data.List != null && data.List.Data != null && data.List.Data.Count > 0 ? "Got Data" : string.Empty) };
            Topic
                .Select<WebServiceInvokeCompleted>()
                .SetHeader("HostName", HttpContext.Current.Request.UserHostName)
                .SetHeader("Url", HttpContext.Current.Request.Url.ToString())
                .Publish(msg);
        }

    }
    public class DataList {
        public List<HelloData> Data { get; set; }
    }
    public class HelloData {
        public string Text { get; set; }
        public DataList List { get; set; }
        public HelloData Parent { get; set; }
    }
}
